//
//  HDModel.m
//  Excited
//
//  Created by X140Yu on 7/17/16.
//  Copyright © 2016 X140Yu. All rights reserved.
//

#import "HDModel.h"
#import "NSObject+YYModel.h"

@implementation HDUser

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];
    if (self) {
        self.username = [aDecoder decodeObjectForKey:@"username"];
        self.cookie = [aDecoder decodeObjectForKey:@"cookie"];
        self.password = [aDecoder decodeObjectForKey:@"password"];
        self.name = [aDecoder decodeObjectForKey:@"name"];
        self.grade = [aDecoder decodeObjectForKey:@"grade"];
        self.college = [aDecoder decodeObjectForKey:@"college"];
        self.speciality = [aDecoder decodeObjectForKey:@"speciality"];
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:self.username forKey:@"username"];
    [aCoder encodeObject:self.password forKey:@"password"];
    [aCoder encodeObject:self.cookie forKey:@"cookie"];
    [aCoder encodeObject:self.name forKey:@"name"];
    [aCoder encodeObject:self.grade forKey:@"grade"];
    [aCoder encodeObject:self.college forKey:@"college"];
    [aCoder encodeObject:self.speciality forKey:@"speciality"];
}

@end

@implementation HDCredit

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super init];
    if (self) {
        self.gpa = [coder decodeObjectForKey:@"gpa"];
        self.passCredit = [coder decodeObjectForKey:@"passCredit"];
        self.failedCredit = [coder decodeObjectForKey:@"failedCredit"];
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:self.gpa forKey:@"gpa"];
    [aCoder encodeObject:self.passCredit forKey:@"passCredit"];
    [aCoder encodeObject:self.failedCredit forKey:@"failedCredit"];
}

@end

@implementation HDScore

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];
    if (self) {
        self.schoolYear = [aDecoder decodeObjectForKey:@"schoolYear"];
        self.term = [aDecoder decodeObjectForKey:@"term"];
        self.cid = [aDecoder decodeObjectForKey:@"cid"];
        self.name = [aDecoder decodeObjectForKey:@"name"];
        self.type = [aDecoder decodeObjectForKey:@"type"];
        self.property = [aDecoder decodeObjectForKey:@"property"];
        self.credit = [aDecoder decodeObjectForKey:@"credit"];
        self.score = [aDecoder decodeObjectForKey:@"score"];
        self.studyMethod = [aDecoder decodeObjectForKey:@"studyMethod"];
        self.remark = [aDecoder decodeObjectForKey:@"remark"];
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:self.schoolYear forKey:@"schoolYear"];
    [aCoder encodeObject:self.term forKey:@"term"];
    [aCoder encodeObject:self.cid forKey:@"cid"];
    [aCoder encodeObject:self.name forKey:@"name"];
    [aCoder encodeObject:self.type forKey:@"type"];
    [aCoder encodeObject:self.property forKey:@"property"];
    [aCoder encodeObject:self.credit forKey:@"credit"];
    [aCoder encodeObject:self.score forKey:@"score"];
    [aCoder encodeObject:self.studyMethod forKey:@"studyMethod"];
    [aCoder encodeObject:self.remark forKey:@"remark"];
}

- (NSString *)printME {
    NSMutableString *retString;
    [retString appendString:[NSString stringWithFormat:@"school year: %@\n", self.schoolYear]];
    [retString appendString:[NSString stringWithFormat:@"term: %@\n", self.term]];
    [retString appendString:[NSString stringWithFormat:@"cid: %@\n", self.cid]];
    [retString appendString:[NSString stringWithFormat:@"name: %@\n", self.name]];
    [retString appendString:[NSString stringWithFormat:@"type: %@\n", self.type]];
    [retString appendString:[NSString stringWithFormat:@"property: %@\n", self.property]];
    [retString appendString:[NSString stringWithFormat:@"creidt: %@\n", self.credit]];
    [retString appendString:[NSString stringWithFormat:@"score: %@\n", self.score]];
    [retString appendString:[NSString stringWithFormat:@"study method: %@\n", self.studyMethod]];
    [retString appendString:[NSString stringWithFormat:@"remark: %@\n", self.remark]];

    return retString;
}

@end


@implementation HDNewsListItem

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];
    if (self) {
        self.nid = [aDecoder decodeObjectForKey:@"nid"];
        self.imgUrl = [aDecoder decodeObjectForKey:@"imgUrl"];
        self.title = [aDecoder decodeObjectForKey:@"title"];
        self.type = [aDecoder decodeObjectForKey:@"type"];
        self.pubTime = [aDecoder decodeObjectForKey:@"pubTime"];
        self.publisher = [aDecoder decodeObjectForKey:@"publisher"];
        self.digest = [aDecoder decodeObjectForKey:@"digest"];
    }

    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:self.nid forKey:@"nid"];
    [aCoder encodeObject:self.imgUrl forKey:@"imgUrl"];
    [aCoder encodeObject:self.title forKey:@"title"];
    [aCoder encodeObject:self.type forKey:@"type"];
    [aCoder encodeObject:self.pubTime forKey:@"pubTime"];
    [aCoder encodeObject:self.publisher forKey:@"publisher"];
    [aCoder encodeObject:self.digest forKey:@"digest"];
}

@end

@implementation HDNews

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];
    if (self) {
        self.nid = [aDecoder decodeObjectForKey:@"nid"];
        self.title = [aDecoder decodeObjectForKey:@"title"];
        self.type = [aDecoder decodeObjectForKey:@"type"];
        self.pubTime = [aDecoder decodeObjectForKey:@"pubTime"];
        self.publisher = [aDecoder decodeObjectForKey:@"publisher"];
        self.content = [aDecoder decodeObjectForKey:@"content"];
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:self.nid forKey:@"nid"];
    [aCoder encodeObject:self.title forKey:@"title"];
    [aCoder encodeObject:self.type forKey:@"type"];
    [aCoder encodeObject:self.pubTime forKey:@"pubTime"];
    [aCoder encodeObject:self.publisher forKey:@"publisher"];
    [aCoder encodeObject:self.content forKey:@"content"];

}

@end

@implementation HDPYFA

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];
    if (self) {
        self.major = [aDecoder decodeObjectForKey:@"major"];
        self.attendYear = [aDecoder decodeObjectForKey:@"attendYear"];
        self.academy = [aDecoder decodeObjectForKey:@"academy"];
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:self.major forKey:@"major"];
    [aCoder encodeObject:self.attendYear forKey:@"attendYear"];
    [aCoder encodeObject:self.academy forKey:@"academy"];

}

- (instancetype)initWithDict:(NSDictionary *)dict {
    if (!dict) {
        return nil;
    }
    if (self = [super init]) {
        if (dict[@"zymc"]) {
            self.major = dict[@"zymc"];
        }

        if (dict[@"njmc"]) {
            self.attendYear = dict[@"njmc"];
        }

        if (dict[@"dwmc"]) {
            self.academy = dict[@"dwmc"];
        }
    }

    return self;
}

@end
